package se.study.thread;

/**
 * @Author: tiger
 * @Date:2018/5/14
 * @Description:
 */
public class WaitAndNoticeTest {
    public static void main(String[] args) throws InterruptedException {
        Thread wait = new Thread(new Wait(), "wait");
        wait.start();// 从打印顺序可以看出，新开线程类似于无参数和返回值的异步方法
        System.out.println("next...");

        Thread notice = new Thread(new Notice(), "notice");
        notice.start();
        System.out.println("end...");

    }

    static private Object obj = new Object();

    static class Wait implements Runnable {

        @Override
        public void run() {
            synchronized (obj) {
                try {
                    System.out.println("Wait start...");
                    obj.wait();
                    System.out.println("Wait end...");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    static class Notice implements Runnable {

        @Override
        public void run() {
            synchronized (obj) {
                System.out.println("Notice start...");
                obj.notify();
                System.out.println("Notice end...");
            }
        }
    }
}
